package com.columboid.protocol.syncml.devicemgmt;

/**
 * Schema fragment(s) for this class:
 * 
 * <pre>
 * &lt;xs:element xmlns:ns=&quot;http://protocol.columboid.com/syncml/devicemgmt&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; name=&quot;Scope&quot;&gt;
 *   &lt;xs:complexType&gt;
 *     &lt;xs:choice&gt;
 *       &lt;xs:element ref=&quot;ns:Permanent&quot;/&gt;
 *       &lt;xs:element ref=&quot;ns:Dynamic&quot;/&gt;
 *     &lt;/xs:choice&gt;
 *   &lt;/xs:complexType&gt;
 * &lt;/xs:element&gt;
 * </pre>
 */
public class Scope {
	private int scopeSelect = -1;
	private static final int PERMANENT_CHOICE = 0;
	private static final int DYNAMIC_CHOICE = 1;
	private Permanent permanent;
	private Dynamic dynamic;

	private void setScopeSelect(int choice) {
		if (scopeSelect == -1) {
			scopeSelect = choice;
		} else if (scopeSelect != choice) {
			throw new IllegalStateException(
					"Need to call clearScopeSelect() before changing existing choice");
		}
	}

	/**
	 * Clear the choice selection.
	 */
	public void clearScopeSelect() {
		scopeSelect = -1;
	}

	/**
	 * Check if Permanent is current selection for choice.
	 * 
	 * @return <code>true</code> if selection, <code>false</code> if not
	 */
	public boolean ifPermanent() {
		return scopeSelect == PERMANENT_CHOICE;
	}

	/**
	 * Get the 'Permanent' element value.
	 * 
	 * @return value
	 */
	public Permanent getPermanent() {
		return permanent;
	}

	/**
	 * Set the 'Permanent' element value.
	 * 
	 * @param permanent
	 */
	public void setPermanent(Permanent permanent) {
		setScopeSelect(PERMANENT_CHOICE);
		this.permanent = permanent;
	}

	/**
	 * Check if Dynamic is current selection for choice.
	 * 
	 * @return <code>true</code> if selection, <code>false</code> if not
	 */
	public boolean ifDynamic() {
		return scopeSelect == DYNAMIC_CHOICE;
	}

	/**
	 * Get the 'Dynamic' element value.
	 * 
	 * @return value
	 */
	public Dynamic getDynamic() {
		return dynamic;
	}

	/**
	 * Set the 'Dynamic' element value.
	 * 
	 * @param dynamic
	 */
	public void setDynamic(Dynamic dynamic) {
		setScopeSelect(DYNAMIC_CHOICE);
		this.dynamic = dynamic;
	}
}
